package ch.pizzapp.kurier.view;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.StringArrayRes;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import ch.pizzapp.kurier.R;
import ch.pizzapp.kurier.data.CategoryData;

/**
 * Shanuka @Cyberlmj 3:08:30 PM Email: shanuka.gayashan@cyberlmj.com
 */
@EViewGroup(R.layout.generator_item)
public class ConnterItem extends RelativeLayout {

	@ViewById(R.id.selectedValue)
	TextView selectedValue;

	@ViewById(R.id.pulusButtons)
	ImageButton pulusButtons;

	@ViewById(R.id.minusButton)
	ImageButton minusButton;
	@StringArrayRes(R.array.user_setting)
	String[] usersetting;

	//List<Size> sizes;
	@AfterViews
	void afterView(){
		selectedValue.setText("0");
	}

	

	
	public void setOnCallBack(Callback callback) {
		mCallback = callback;

	}

	public ConnterItem(final Context context) {
		super(context);

	}

	public interface Callback {
		void onClicked(int size);

	}

	private Callback mCallback;
	int selectVale = 0;

	// List<String> wordList;

	@Click({ R.id.pulusButtons, R.id.minusButton })
	void onClick(View vuew) {
		switch (vuew.getId()) {
		case R.id.pulusButtons:
			System.out.println("pulusButtons");
			puls();
			break;
		case R.id.minusButton:

			System.out.println("minus");
			minus();
			break;

		default:
			break;
		}
	}

	public ConnterItem(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public void bind(final CategoryData categoryData) {
		selectedValue.setText(categoryData.getTitle());

	}

	void minus() {
		if (selectVale > 0) {
			selectVale = selectVale - 1;
			selectedValue.setText(String.valueOf(selectVale));
			mCallback.onClicked(selectVale);
		}

	}

	void puls() {
		if (selectVale < 100) {
			selectVale = selectVale + 1;
			selectedValue.setText(String.valueOf(selectVale));
			mCallback.onClicked(selectVale);
		}
	}
}
